﻿using Digitalmes.Domain.Entities.Mes.Masters;

namespace Digitalmes.Application.Mes.Masters.Lines.Queries;

/// <summary>
/// 产线查询命令。
/// </summary>
/// <param name="LineName">产线名称</param>
public record GetLineListQuery(string? LineName) : IRequest<IResult<List<MdLineDto>>>;

internal sealed class GetLineListQueryHandler(IRepository<MdLine> repo) : IRequestHandler<GetLineListQuery, IResult<List<MdLineDto>>>
{
    public async Task<IResult<List<MdLineDto>>> Handle(GetLineListQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.AsQueryable()
            .WhereIF(!string.IsNullOrEmpty(request.LineName), m => m.LineName.Contains(request.LineName!))
            .ToListAsync(cancellationToken);
        return Result.From(items.Adapt<List<MdLineDto>>());
    }
}
